// import Vue from 'vue';
import Vuex from 'vuex';
import VuexPersist from 'vuex-persist';

// Vue.use(Vuex);

const state = {
  token: '', // token
  userinfo: {}, // 用户个人信息
  menus: {}, // 用户授权目录
  btns: {} // 当前目录授权按钮
};

const mutations = {
  setToken (state, token) {
    state.token = token;
  },
  setInfo (state, userinfo) {
    state.userinfo = userinfo;
  },
  setMenus (state, menus) {
    state.menus = menus;
  },
  setBtns (state, btns) {
    state.btns = btns;
  }
};

const vuexPersist = new VuexPersist({
  storage: window.localStorage,
  reducer: state => ({
    token: state.token,
    userinfo: state.userinfo,
    menus: state.menus,
    btns: state.btns
  })
});

export default new Vuex.Store({
  // actions,
  // getters,
  state,
  mutations,
  plugins: [vuexPersist.plugin]
});
